﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using CRM.BLL;
using CRM.Entity;
using DP.Common;

namespace CRM.Web.Service
{
    /// <summary>
    /// CallLog 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消对下行的注释。
     [System.Web.Script.Services.ScriptService]
    public class CallLog : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public string Write(string ani, string dnis, string state, string ucid, string direction, string stime, string etime, string dtmf, string isconnect, string userId, string userName, string loginName, string seatId, string ext, string businessDivisionName, string businessDivisionCode)
        {            
            string rel = "Success";
            if (String.IsNullOrEmpty(ucid))
            {
                return rel;
            }
            try
            {
                T_CALLLOG_BLL callLogBll = new T_CALLLOG_BLL();
                T_CALLLOG_Entity entity = new T_CALLLOG_Entity();
                entity.ANI = ani;
                entity.BUSINESSDIVISIONCODE = businessDivisionCode;
                entity.BUSINESSDIVISIONNAME = businessDivisionName;
                entity.CREATETIME = DateTime.Now;
                entity.DIRECTION = direction;
                entity.DNIS = dnis;
                entity.ETIME = etime;
                entity.EXT = ext;
                entity.LOGINNAME = loginName;
                entity.SEATID = seatId;
                entity.STATUS = state;
                entity.STIME = stime;
                entity.UCID = ucid;
                entity.USERID = StringHelper.ToLong(userId);
                entity.USERNAME = userName;
                entity.DTMF = dtmf;
                entity.ISCONNECT = isconnect;

                callLogBll.Insert(entity);
            }
            catch (Exception ex)
            {
                string str = "ani={0}, dnis={1}, state={2}, ucid={3}, direction={4}, stime={5}, etime={6}, userId={7}, userName={8}, loginName={9}, seatId={10}, ext={11}, businessDivisionName={12}, businessDivisionCode={13}, dtmf={14}, isconnect={15}";
                LogHelper.WriteLog("WebServiceTest", String.Format(str, ani, dnis, state, ucid, direction, stime, etime, userId, userName, loginName, seatId, ext, businessDivisionName, businessDivisionCode, dtmf, isconnect));

                LogHelper.WriteLog("WebServiceTest", ex.Message);
                rel = "Failure";
            }
            return rel;
        }

    }
}
